package com.wechat.utils.kit;

import java.io.UnsupportedEncodingException;

public class SMSKit {

	/**
	 * 发送手机短信url
	 */
	public static String	sendUrl	= "http://222.73.117.158/msg/HttpSendSM";

	/**
	 * 参数 $1 用户名 $2 密码 $3 手机号 $4 短信信息 $5 签名表示谁发送
	 */
	public static String	param	= "account=$1&pswd=$2&mobile=$3&msg=验证码：$4。印象智慧游帐号安全验证，请勿将验证码提供给他人。【$5】&needstatus=true";
	
	/**
	 * 用户名
	 */
	public static String	account	= "Yzw888";
	
	/**
	 * 密码
	 */
	public static String	pswd	= "Yzw888888";
	
	/**
	 * 发送签名
	 */
	public static String	qianm	= "印象智慧游";
	
	public static String sendMsg(String mobile, String msg){
		String params;
        try {
	        params = "account="+account+"&pswd="+pswd+"&mobile="+mobile+"&needstatus=true&msg="+java.net.URLEncoder.encode(msg, "utf-8");
        } catch (UnsupportedEncodingException e) {
	        e.printStackTrace();
	        params = "account="+account+"&pswd="+pswd+"&mobile="+mobile+"&needstatus=true&msg="+msg;
        }
		return HttpKit.post(sendUrl, params+"【"+qianm+"】");
	}
	
	/**
	 * 发送验证码
	 * @param mobile
	 * @param code
	 * @return Boolean
	 */
	public static Boolean sendCode(String mobile, String code){
		String msg = "验证码："+code+"。印象智慧游帐号安全验证，请勿将验证码提供给他人。【"+qianm+"】";
		String returnStr = sendMsg(mobile, msg);
		return returnStr.indexOf(",0") >= 1;
	}
	public static Boolean sendCodel(String mobile, String cadeno,String code){
		String msg = "团员邀请码:"+code.substring(code.length()-6)+"。团队编号:"+cadeno+"。【"+qianm+"】";
		String returnStr = sendMsg(mobile, msg);
		return returnStr.indexOf(",0") >= 1;
	}
	
	/**
	 * 发送验证码，自动生成6位数字验证码
	 * @param mobile
	 * @return
	 */
	public static String sendCode(String mobile){
		String code = "";
		for (int i = 0; i < 6; i++){
			code += (int)(Math.random() * 10);
		}
		if(sendCode(mobile, code)){
			return code;
		}
		return null;
	}
	
	/**
	 * 转账成功后，发信息给用户
	 * @param mobile
	 * @param money
	 * @return Boolean
	 */
	public static Boolean sendAuther(String mobile,float money){
		String msg = "尊敬的商户：已经向您转账"+money+"元。【"+qianm+"】";
		String returnStr = sendMsg(mobile, msg);
		return returnStr.indexOf(",0") >= 1;
	}


	public static void main(String[] args) {
		/*System.out.println(sendCodel("15773010413","555"));*/
	}

//	class Result{
//		public String msgid;
//		public String statusCode;
//	}
}
